﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using oLGame.Game.Players;
using oLGame.Game.Items;
namespace oLGame.Game.World
{
    class Room
    {
        // Each room has a specific ID much like each Entity does as well.
        public static UInt64 roomCount = 0;
        private UInt64 id = 0;

        // Room contains a list of players.
        protected List<Entity> objectsInRoom = new List<Entity>();
        // Room contains N, S, E, W exits
        public RoomExits roomExits;

        // Each room has a name.
        protected String roomName = "unknown";

        public Room()
        {
            RoomID = roomCount++;
        }

        public void AddEntityToRoom(Entity what)
        {
            if (!IsEntityInRoom(what))
                Objects.Add(what);
        }

        public void RemoveEntityFromRoom(Entity what)
        {
            if (IsEntityInRoom(what))
                Objects.Remove(what);
        }

        public bool IsEntityInRoom(Entity what)
        {
            if (what != null)
            {
                Entity result = objectsInRoom.Find(
                    delegate(Entity entity)
                    {
                        return entity.EntityID == what.EntityID;
                    }
                );
                if (result != null)
                    return true;
            }
            return false;
        }

        public List<Player> Players
        {
            get
            {
                return Objects.OfType<Player>().ToList<Player>();
            }
        }

        public List<Item> Items
        {
            get
            {
                return Objects.OfType<Item>().ToList<Item>();
            }
        }

        public List<Entity> Objects
        {
            get
            {
                return objectsInRoom;
            }
        }

        public String Name
        {
            get
            {
                return roomName;
            }
            set
            {
                roomName = value;
            }
        }

        public UInt64 RoomID
        {
            get
            {
                return id;
            }
            set
            {
                id = value;
            }
        }
    }
}

 